<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>分享二维码</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/yzl.css"/>

</head>
<body>
<div id="blank" class="header">
    <div id="back" v-back.tapmode class="back"></div>
    <span class="title">分享二维码</span>
</div>
<div id="app" class="main-container" style="text-align: center;" v-cloak>
    <p style="margin-top:65px;">我的邀请码: {{infos.invite_code}}</p>
    <img :src="qrcode" style="width:180px;margin-top:25px;">
    <p style="text-align: left;margin:60px 40px;">只要好友通过链接注册成功，您就可以得到相应的分享奖励以及推广收益。</p>
    <div class="shareQrcode-icons">
        <a v-myclick="['timeline', share_wx]">
            <img v-src="'../../image/share_btn_moments.png'">
            <p>朋友圈</p>
        </a>
        <a v-myclick="['session', share_wx]">
            <img v-src="'../../image/share_btn_wechat.png'">
            <p>微信好友</p>
        </a>
        <a v-myclick="share_qq">
            <img v-src="'../../image/share_btn_qq.png'">
            <p>QQ好友</p>
        </a>
    </div>
</div>
</body>
<script src="../../script/api.js"></script>
<script src="../../script/vue.js"></script>
<script src="../../script/app.js"></script>
<script src="../../script/common.js"></script>
<script src="../../script/url.js"></script>
<script>

    var qrcode,
        infos,
        scanner,
        wx,
        vm;
    apiready = function () {
        setBSImg();
        new Vue({
            el: '#blank'
        });
        showProgress();
        scanner = api.require('FNScanner');
        wx = api.require('wx');

        getInfos();

        addListeners();
    };

    function getInfos() {
        var data = {
            member_id:getPrefs('member_id')
        };

        var callback = function (ret) {
            infos = ret.content;
            qrcode = infos.qrcode;
            encodeImg(qrcode);
        };
        pinet.post(URL.shareQrcode, data, callback);
    }

    function encodeImg(qrcode) {
        scanner.encodeImg({
            content: qrcode,
            saveImg: {
                path: 'fs://qrcode.png',
                w:400,
                h:400
            }
        }, function (ret) {
            if(ret.status){
                initApp(ret.imgPath);
                api.parseTapmode();
            }
        })
    }

    function initApp(qrcode) {
        vm = new Vue({
            el: '#app',
            data: {
                qrcode: qrcode,
                infos: infos
            },
            methods: {
                share_wx: function (scene) {
                    share_wx(scene, vm.infos.share);
                },
                share_qq: function () {
                    share_qq(vm.infos.share);
                }
            }
        });
    }

    function addListeners() {
        api.addEventListener({
            name: 'viewappear'
        }, function () {
            onPageStart();
        });

        api.addEventListener({
            name: 'viewdisappear'
        }, function (ret, err) {
            onPageEnd();
        });

        api.addEventListener({
            name: 'keyback'
        }, function (ret, err) {
            onPageEnd();
            api.closeWin();
        });
    }
    
</script>
</html>
